home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / indx18eu.zip / COMPARE.ASM < prev    next >
Assembly Source File  |  1991-03-14  |  5KB  |  109 lines

  1. %TITLE "Compare any two variables from TP"
  2.  
  3. ;-----------------------------------------------------------------------;
  4. ;                                                                       ;
  5. ;  PURPOSE :    This assembly PROC will compare ANY two variable        ;
  6. ;               declared in in the calling program.  This PROC follows  ;
  7. ;               the Turbo Pascal calling conventions.                   ;
  8. ;                                                                       ;
  9. ;  SYSTEM  :  IBM PS/2 Model 30/286                                     ;
  10. ;                                                                       ;
  11. ;  AUTHOR  :  Thomas E. Jenkins, Jr.                                    ;
  12. ;                                                                       ;
  13. ;-----------------------------------------------------------------------;
  14.  
  15.                 .MODEL TPascal
  16.  
  17.                 .CODE
  18.  
  19. ;---------------  Insert PUBLIC code declarations here
  20.  
  21.                 PUBLIC    Compare
  22.  
  23. %NEWPAGE
  24. ;---------------------------------------------------------------;
  25. ;--  FUNCTION comapre ( VAR var1                 ;            --;
  26. ;--                     VAR var2                 ;            --;
  27. ;--                         strng                : BOOLEAN ;  --;
  28. ;--                         count                : WORD )     --;
  29. ;--                                              : INTEGER    --;
  30. ;--                                                           --;
  31. ;---------------------------------------------------------------;
  32. ;--                                                           --;
  33. ;--   INPUT :                                                 --;
  34. ;--             var1    :  POINTER                            --;
  35. ;--                        - any VAR name                     --;
  36. ;--             var2    :  POINTER                            --;
  37. ;--                        - any VAR name                     --;
  38. ;--             strng   :  BOOLEAN                            --;
  39. ;--                          · will skip length byte if true  --;
  40. ;--                        - FALSE for pascal or zero         --;
  41. ;--                        - TRUE  for pascal or non-zero     --;
  42. ;--             count   :  WORD                               --;
  43. ;--                        -  a non-zero value indicating the --;
  44. ;--                           number of bytes to compare.     --;
  45. ;--                                                           --;
  46. ;---------------------------------------------------------------;
  47. ;--                                                           --;
  48. ;--  RETURN:  -1 var1 < var2                                  --;
  49. ;--            0 var1 = var2                                  --;
  50. ;--            1 var1 > var2                                  --;
  51. ;--                                                           --;
  52. ;---------------------------------------------------------------;
  53. ;--                                                           --;
  54. ;--  EXAMPLE CALL FROM PASCAL:                                --;
  55. ;--                                                           --;
  56. ;--  eq := Compare ( str1 , str2 , TRUE , SizeOf ( str1 ) ) ; --;
  57. ;--                                                           --;
  58. ;---------------------------------------------------------------;
  59.  
  60. Compare PROC  FAR var1:DWORD,var2:DWORD,strng:BYTE,count:WORD
  61.  
  62.                 LOCALS  @@
  63.  
  64.                 cld                     ;Compare from begining
  65.  
  66.                 mov     dx,ds           ;Save calling routine's ds
  67.  
  68.                 lds     si,var1         ;Set to first  address
  69.                 les     di,var2         ;Set to second address
  70.  
  71.                 mov     cx,count        ;Get # bytes to compare
  72.  
  73.                 cmp     strng,0         ;String ?
  74.                 jz      @@NOTSTRING     ;No, comapre like normal
  75.  
  76.                 dec     cx              ;Take one from str length
  77.                 inc     si              ;Skip length byte
  78.                 inc     di              ;Skip length byte
  79.  
  80. @@NOTSTRING:
  81.                 jcxz    @@EQUAL         ;Length > 0 ?
  82.                                         ; if not, report that two zero length
  83.                                         ; variables are equal.
  84.  
  85.                 repe    cmpsb           ;Compare till one byte <> paired
  86.  
  87.                 je      @@EQUAL         ;var1 = var2
  88.                 ja      @@ABOVE         ;var1 > var2
  89.  
  90.                 mov     ax,0FFFFh       ;var1 < var2
  91.                 mov     ds,dx
  92.                 ret
  93.  
  94. @@ABOVE:
  95.                 mov     ax,00001h       ;Set var1 > var2
  96.                 mov     ds,dx           ;Restore ds
  97.                 ret
  98.  
  99. @@EQUAL:
  100.                 xor     ax,ax           ;Set var1 = var2
  101.                 mov     ds,dx           ;Restore ds
  102.                 ret
  103.  
  104. ENDP            Compare
  105.  
  106. ENDS            CODE
  107.  
  108.                 END                     ; END OF SOURCE
  109.